package dk.dashboardFP.panels.fontPreview {
	import dk.dashboardFP.shapes.Box;

	import flash.events.MouseEvent;

	import dk.dashboardFP.panels.ui.text.DFPAdvancedLabel;

	import flash.display.Sprite;
	import flash.text.Font;

	/**
	 * @author josef
	 */
	public class FontPreview extends Sprite {
		private var _font : Font;
		private var _fontLabel : DFPAdvancedLabel;
		private var _previewLabel : DFPAdvancedLabel;
		private var _margin : Number = 2;
		private var _back : Box;

		public function FontPreview(font : Font) {
			_font = font;
			super();
			
			setupElements();
		}

		private function setupElements() : void {
			
			// sectionName 
			_fontLabel = new DFPAdvancedLabel("", 10, 0xffffff);
			addChild(_fontLabel);
			
			_fontLabel.sHtmlText = "<font color='#ffffff'>" + _font.fontName + "       <font color='#999999'>Style : </font>" + _font.fontStyle + "</font>";
			
			_fontLabel.bSelectable = true;
			
			// preview label 
			_previewLabel = new DFPAdvancedLabel("The quick brown fox jumps over the lazy dog", 14, 0xffffff, false, _font.fontName);
			addChild(_previewLabel);
			
			_previewLabel.y = _fontLabel.height+2;
			
			// draw whit back 
			_back = new Box(_previewLabel.width + _margin * 2, _previewLabel.height + _margin * 2, 0xffffff, 1, 3);
			addChildAt(_back, 0);
			
			_back.alpha = 0;
			
			_back.x = _previewLabel.x - _margin;
			_back.y = _previewLabel.y - _margin;
			
			// register 
			addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
			addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
			
			_back.mouseEnabled = false;
			_previewLabel.mouseEnabled = false;
		}

		private function onOut(event : MouseEvent) : void {
			//_fontLabel.sHtmlText = "<font color='#ffffff'>"+_font.fontName+"       <font color='#999999'>Style : </font>" + _font.fontStyle+"</font>";
			_previewLabel.uintColor = 0xffffff;
			
			_back.alpha = 0;
		}

		private function onOver(event : MouseEvent) : void {
			_previewLabel.uintColor = 0x000000;
			//	_fontLabel.sHtmlText = "<font color='#000000'>"+_font.fontName+"       <font color='#666666'>Style : </font>" + _font.fontStyle+"</font>";

			_back.alpha = 1;
		}
	}
}
